package com.base.myproject.client.HR.Self;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.LasyObejct;
import com.base.myproject.client.busi.BO.BusiObject;
import com.base.myproject.client.jdbc.StoreInfo;
import com.base.myproject.client.tools.Tools;
import com.base.myproject.client.ui.BaseFormPanel;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.Style.VerticalAlignment;
import com.extjs.gxt.ui.client.core.XTemplate;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.ListView;
import com.extjs.gxt.ui.client.widget.form.TextArea;
import com.extjs.gxt.ui.client.widget.layout.TableData;
import com.extjs.gxt.ui.client.widget.layout.TableLayout;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;

public class SelfBcode_Extdata extends LayoutContainer implements LasyObejct {

	BaseStore<BusiObject> mainstore = null;
	
	public SelfBcode_Extdata(BaseStore<BusiObject> mainstore) {
		this.mainstore = mainstore;
		init();
	}

	private void init() {
		setLayout(new TableLayout(2));
		
		TableData td1 = new TableData();
		TableData td2 = new TableData();
		TableData td3 = new TableData();
		
		td1.setColspan(2);
		td2.setColspan(1);
		td3.setColspan(1);
		
		td2.setVerticalAlign(VerticalAlignment.TOP);
		td3.setVerticalAlign(VerticalAlignment.TOP);

		HorizontalPanel hPanel = new HorizontalPanel();
		hPanel.setSpacing(5);
		add(hPanel, td1);

		add(CreateView(), td2);
		
		VerticalPanel vpanel = new VerticalPanel();
		add(vpanel, td3);

	}

	BaseStore<BusiObject> store = null;
	ListView<BusiObject> view = null;

	BaseStore<BusiObject> getStore() {
		if (store == null) {
			createStore();
		}
		return store;
	}

	BaseStore<BusiObject> createStore() {
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.setTotalName("totle");
		type.addField("icode");
		type.getField("icode").setType(Long.class);
		type.addField("bcode");
		type.getField("bcode").setType(String.class);
		type.addField("imagepath");
		type.getField("imagepath").setType(String.class);
		type.addField("mark");
		type.getField("mark").setType(String.class);
		StoreInfo info = new StoreInfo();
		info.setTablename("bcode_extdata");
		info.setKeyname(new String[] { "icode" });
		info.setSql("select * from bcode_extdata where bcode='{bcode}'");
		info.setParent(mainstore);// 关联主表
		info.setLinkparentcolumns(new String[] { "bcode" }); // 关联主表字段
		info.setLinkparent_chile_columns(new String[] { "bcode" });//
		// 关联主表字段
		store = new BaseStore<BusiObject>(type, info);
		return store;
	}
	
	public ContentPanel CreateView() {
		final ContentPanel panel = new ContentPanel();
		panel.setHeaderVisible(false);
		// panel.setCollapsible(true);
		// panel.setAnimCollapse(false);
		panel.setFrame(true);
		panel.setId("images-view");
		panel.setBodyBorder(false);

		view = new ListView<BusiObject>() {
			@Override
			protected BusiObject prepareData(BusiObject model) {
				return model;
			}
		};

		view.setTemplate(getTemplate());
		view.setStore(createStore());
//		view.setHeight(300);
//		view.setWidth(500);
		view.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
		view.setItemSelector("div.thumb-wrap");
		panel.add(view);
		Tools.setResize(view,0.53,0.85);
		Tools.setResize(panel,0.54,0.85);
		return panel;
	}

	private native String getTemplate() /*-{
		return ['<tpl  for=".">', 
		'<div class="thumb-wrap" id="sss" style="border: 1px solid white;float:left;">',

		'<div class="thumb" ><img style="width:200px;height:200px;border:5px double #eee;margin: 3px 2px 2px 3px" src="{imagepath}" title="{mark}"></div>', 
		'<span class="x-editable" style="float:left" >&nbsp;</span></div>', 
		'</tpl>',
		'<div class="x-clear"></div>'].join("");
	}-*/;

	public native String getDetailTemplate() /*-{
		return ['<div class="details">', 
		'<tpl for=".">', 
		'<img style="width:100px;height:100px;border:5px double #eee;margin: 3px 2px 2px 3px" src="{imagepath}"><div class="details-info">', 
		'<b></b>', 
		'<span></span>', 
		'<b></b>', 
		'<span>{mark}</span>', 
		'<b></b>', 
		'<span></span></div>', 
		'</tpl>', 
		'</div>'].join("");
	}-*/;
	
	@Override
	public boolean isopen() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean open() {
		// TODO Auto-generated method stub
		return false;
	}

	public void setStore(BaseStore<BusiObject> store) {
		this.store = store;
	}
}
